package programmierung.aufgabe2;

public final class Complex {
	private final double real;
	private final double imag;
	
	
	public Complex(double re, double im) {
		real = re;
		imag = im;
	}
	
	public Complex add(Complex b) {
		return new Complex(this.real + b.real, this.imag + b.imag);
	}
	
	public Complex subtract(Complex b) {
		return new Complex(this.real - b.real, this.imag - b.imag);
	}
	
	public Complex multiply(Complex b) {
		return new Complex((this.real * b.real) - (this.imag * b.imag), (this.real * b.imag) + (this.imag * b.real));
		
	}
	
	public Complex divide(Complex b) {
		double tempR = ((this.real*b.real) + (this.imag*b.imag)) / (Math.pow(b.real, 2) + Math.pow(b.imag, 2));
		double tempI = ((this.imag*b.real) - (this.real*b.imag)) / (Math.pow(b.real, 2) + Math.pow(b.imag, 2));
		return new Complex(tempR, tempI);
	}

	public double getReal() {
		return real;
	}

	public double getImag() {
		return imag;
	}
	
}
